from flask import render_template
from blueprints import check_blueprint
from models import QueryMultipleInstances, Check, QueryOneInstance, Blog, PackInstance, Admin
from tools.decorate import pack_session


@check_blueprint.route('/admin/page/check', methods=['GET'])
@pack_session
def get_admin_page_of_check(data):
    checks = QueryMultipleInstances(Check,{})

    blog_dict=[]
    for i in checks:
        blog = QueryOneInstance(Blog,{'id':i.pid})
        if blog:
            blog_dict.append(blog)

    if blog_dict:
        data.update(PackInstance(blog_dict))
    data['writeable']=False

    admin = QueryOneInstance(Admin,{'uid':data['session']['uid']})

    if admin:
        data['checkable']=True

    return render_template('pages/check/blog.html',data=data)